/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/*
* Copyright 2010, Center for Advanced Information Systems, Nanyang Technological University
*
* File name:    DBformat.java
*
* Abstract: Convert Standard format file to DB table format
*
* Current Version:      0.1
* Auther:               Jin Changjiu
* Modified Date:        June.3,2009
*
*/
package gblend.formatcovert;

/**
 *
 * @author cjjin
 */

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.Vector;
public class DBformat {

    private static Vector<Integer> h = new Vector<Integer>();
    public static void main (String[] args) throws FileNotFoundException 
    {
         String filename = "data/Syn/120k/Syn120k";
         formatDotFile(filename);
    }
    
  
    public static void formatDotFile(String filename)
    {
	String output1="data/Syn/120k/VT.txt", output2 = "data/Syn/120k/ET.txt";
        String strLine = null;
	FileOutputStream outStream1,outStream2;
	PrintStream p;
        PrintStream q;
	FileInputStream inStream;
	DataInputStream in;
	BufferedReader br;
              
	File fin=new File(filename);
	File fout1=new File(output1);
        File fout2=new File(output2);
	if(fin.exists())
	{
            try {
                                       
        	outStream1=new FileOutputStream(fout1,false);
                outStream2=new FileOutputStream(fout2,false);
            	inStream=new FileInputStream(fin);
		// Connect print stream to the output stream
                p = new PrintStream( outStream1 );
                q = new PrintStream( outStream2 );
		// Get the object of DataInputStream
                in = new DataInputStream(inStream);
                br = new BufferedReader(new InputStreamReader(in));
		//Read file line by line
    		try {
                    
                      int graphnum = -1;
                      String nline = null;
                      String eline = null;
                      while ((strLine = br.readLine()) != null)
                      {
                           // Print the content on the console
                           if(strLine.contains("t #"))
                           {
                               graphnum++;
                           }
                           else if(strLine.contains("v"))
                           {
                               nline = strLine.replace("v ", graphnum+" ");
                               p.println(nline);
                           }
                           else if(strLine.contains("e"))
                           {
                                eline = strLine.replace("e ", graphnum+" ");
                                q.println(eline);
                           }
                       
                       }

			//Close the input stream
                        in.close();
                        p.close();
                        q.close();
					
			} 
			catch (IOException e) 
			{
			// TODO Auto-generated catch block
                            e.printStackTrace();
			}
                    } catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			}
		}

	}
       
   
}
